﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;

namespace ServiceController
{
    public delegate DataAccess.DataAccessResult UpdateDeploymentStatusDelegate(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String Status);
    public partial class ServiceController
    {
        UpdateDeploymentStatusDelegate _UpdateDeploymentStatusDelegate;
        public void UpdateDeploymentStatusAsync(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String Status, object UserState)
        {
            _UpdateDeploymentStatusDelegate.BeginInvoke(SubscriptionID, CertificatePath, ServiceName, DeploymentSlot, Status,
                new AsyncCallback(UpdateDeploymentStatusCallback), UserState);
        }

        private void UpdateDeploymentStatusCallback(IAsyncResult ar)
        {
            AsyncResult aresult = (AsyncResult)ar;
            DataAccess.DataAccessResult result = _UpdateDeploymentStatusDelegate.EndInvoke(ar);
            OnUpdateDeploymentStatusComplete(new ServiceControllerEventArgs()
            {
                error = result.Error,
                UserState = ar.AsyncState,
                IsOperationSuccessful = result.IsOperationSuccessful,
                RequestID = result.RequestID,
            });
        }

        private DataAccess.DataAccessResult UpdateDeploymentStatus(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String Status)
        {
            DataAccess.DataAccessResult result = da.UpdateDeploymentStatus(SubscriptionID, CertificatePath, ServiceName, DeploymentSlot,Status);
            return result;
        }
    }
}
